package com.ang.behavior.interpreter;

import java.util.StringTokenizer;

/**
 * @author ANG.YU
 * @date 2020-09-22 09:49
 */
public class StringTokenizerTest {
    public static void main(String[] args) {
        String str = "runoob,google,taobao,facebook,zhihu";
        // 以 , 号为分隔符来分隔字符串
        StringTokenizer st=new StringTokenizer(str,",");
        while(st.hasMoreTokens()) {
            System.out.println(st.nextToken());
        }

        System.out.println("使用第一种构造函数：");
        StringTokenizer st1 = new StringTokenizer("Hello Runoob How are you", " ");
        while (st1.hasMoreTokens()) {
            System.out.println(st1.nextToken());
        }

        System.out.println("使用第二种构造函数：");
        StringTokenizer st2 = new StringTokenizer("JAVA : Code : String", " :");
        while (st2.hasMoreTokens()) {
            System.out.println(st2.nextToken());
        }

        System.out.println("使用第三种构造函数：");
        StringTokenizer st3 = new StringTokenizer("JAVA : Code : String", " :",  true);
        while (st3.hasMoreTokens()) {
            System.out.println(st3.nextToken());
        }
    }
}
